

package retrival;

/**
 *
 * @author Administrator
 */
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.Event;
import java.util.Date;
import java.util.ArrayList;
import java.io.*;

public class retrival
{
   public static void main(String[] args)
   {
      InformationFrame frame = new InformationFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }
}

/**
   A frame that contains a panel with drawings
*/
class InformationFrame extends JFrame
{
   public InformationFrame()
   {
      setTitle("StockInformation");
      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

      TPsOnSlidingWindow P = new TPsOnSlidingWindow("^HSI","2000-01-01","2010-05-30");//"^HSI","2000-5-30","2010-05-30");
      TPsOnSlidingWindow Q = new TPsOnSlidingWindow("^HSI","2000-01-01","2007-05-31");
      Experiments panel1 = new Experiments(P);
      add(panel1);

      int [] temp1 = new int [4];
      temp1[0]=P.TPFinal1.length;
      temp1[1]=P.TPFinal2.length;
      temp1[2]=P.TPFinal3.length;
      temp1[3]=P.TPFinal4.length;

      int [] temp2 = new int [4];
      temp2[0]=Q.TPFinal1.length;
      temp2[1]=Q.TPFinal2.length;
      temp2[2]=Q.TPFinal3.length;
      temp2[3]=Q.TPFinal4.length;

      int [] temp3 = new int [4];
      temp3[0]=sharedPoints(P.TPFinal1,Q.TPFinal1);
      temp3[1]=sharedPoints(P.TPFinal2,Q.TPFinal2);
      temp3[2]=sharedPoints(P.TPFinal3,Q.TPFinal3);
      temp3[3]=sharedPoints(P.TPFinal4,Q.TPFinal4);

      print("C:\\SlidingWindow\\PointsPreservedAfterAddingNewdata_TPofSlidingW..txt",temp1,temp2,temp3);

   }
private int sharedPoints(int [] P1, int[]P2)
   {
       int  Count = 0;

       for(int i =0;i<P1.length;i++)
       {
           for(int j =0;j<P2.length; j++)
           {
               if(P1[i]==P2[j])
               {
                   Count++;
                   j = P2.length;
               }
               else if(P1[i] < P2[j])
                   j = P2.length;
               else
                   ;
           }
       }
       return Count;
   }

 public void print  (String s, int[] arr1, int[] arr2,int[] arr3)
    {
      try
      {
       FileWriter fileWriter=new FileWriter(s);

       fileWriter.write("The first column is the No. of points from P1;" +"\r\n The second column is the No. of points from P2\r\n" +" The third is SharedPoints"+"\r\n");
       for (int i = 0; i < arr3.length; i++) {
        fileWriter.write(String.valueOf(arr1[i]) +" "+String.valueOf(arr2[i]) +" "+String.valueOf(arr3[i])+"\r\n");
         }
       fileWriter.flush();
       fileWriter.close();
       }catch (Exception e) {
             e.printStackTrace();
       }
    }
   public static final int DEFAULT_WIDTH = 1400;
   public static final int DEFAULT_HEIGHT = 1000;
}



